package top.go2do.common.exception;

/**
 * @author xingyuji
 * @date 2025/3/9 18:15
 * @description
 */
/**
 * 自定义业务异常，用于全局统一处理业务错误
 */
public class BusinessException extends RuntimeException {
    private final int code;
    private final String msgKey;
    private final Object[] args;

    // 使用枚举简化构造
    public BusinessException(int code, String msgKey) {
        this(code, msgKey, null, null);
    }

    public BusinessException(int code, String msgKey, Object[] args) {
        this(code, msgKey, args, null);
    }

    public BusinessException(int code, String msgKey, Object[] args, Throwable cause) {
        super(msgKey, cause);
        this.code = code;
        this.msgKey = msgKey;
        this.args = args != null ? args : new Object[0];
    }

    // 使用枚举简化构造
    public BusinessException(BusinessResultCode businessResultCode) {
        this(businessResultCode.getCode(), businessResultCode.getMsgKey());
    }

    public BusinessException(BusinessResultCode businessResultCode, Object[] args) {
        this(businessResultCode.getCode(), businessResultCode.getMsgKey(), args);
    }

    public BusinessException(BusinessResultCode businessResultCode, Object[] args, Throwable cause) {
      this(businessResultCode.getCode(), businessResultCode.getMsgKey(), args, cause);
    }

    // Getter
    public int getCode() {
        return this.code;
    }

    public String getMsgKey() {
        return this.msgKey;
    }

    public Object[] getArgs() {
        return args;
    }
}
